package data;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;


public class DepartmentList extends ListResponse {
	private List<DepartmentData> mResult = new ArrayList<>();
	
	public DepartmentList(int exitCode, DepartmentData[] products) {
		this.mExitCode = exitCode;
		if (products != null)
			for (DepartmentData productInfo : products)
				mResult.add(productInfo);
	}

	public DepartmentList(int exitCode, List<DepartmentData> products) {
		this.mExitCode = exitCode;
		if (products != null)
			for (DepartmentData productInfo : products)
				mResult.add(productInfo);
	}
	
	public List<DepartmentData> getList() {
		return mResult;
	}
	
	public final static JsonDeserializer<DepartmentList> deserializer = new JsonDeserializer<DepartmentList>() {

		@Override
		public DepartmentList deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
				throws JsonParseException {
			
			int exitCode = json.getAsJsonObject().get("exitCode").getAsInt();
			DepartmentData[] products = context.deserialize(json.getAsJsonObject().get("result"), DepartmentData[].class);
			return new DepartmentList(exitCode, products);
		}
	};
}
